/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#include "PartitionElementCacheService.h"

#include <cassert>

#include "DBManager/Common/ServiceMacro.h"
#include "DBManager/IRepository/Input/Element/IPartitionElementCacheRepository.h"

using namespace SG::DBManager;

SERVICE_REG_WITH_DBM_IMPL (PartitionElementCacheService, IPartitionElementCacheRepository)

PartitionElementCacheService::PartitionElementCacheService (DBServiceFactory* const           dbServiceFactory,
                                                            IPartitionElementCacheRepository& repos)
    : InputServiceBase<IRepos> (dbServiceFactory, repos)
{}

PartitionElementCacheService::~PartitionElementCacheService () = default;

std::vector<SG::DataStructure::Common::Id> PartitionElementCacheService::GetElementsByPartition (SG::DataStructure::Common::Id partitionId)
{

    // 通过ID查找分区缓存
    ServiceDataType result;
    auto            status = FindById (partitionId, result);

    std::vector<SG::DataStructure::Common::Id> elementIds;

    if (status == SG::DataStructure::Common::Status::STATUS_Success)
    {
        elementIds.reserve (result.m_subs.size ());
        // 提取单元ID
        for (const auto& eid : result.m_subs)
        {
            elementIds.push_back (eid);
        }
    }

    return elementIds;
}
